#!/bin/sh
#Barry Kauler, Oct. 2011
#called via udev /etc/udev/rules.d/88-puppy-autodetect.rules
#111007 first release.
#111010 maybe wait until delayedrun has done its stuff.

[ ! "$1" ] && exit
[ "`pidof X`" = "" -a "`pidof Xorg`" = "" ] && exit #X not running.
export PATH='/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/root/my-applications/bin'
export DISPLAY=':0'

#111010 maybe wait until delayedrun has done its stuff...
EXCNT=0
while [ ! -f /tmp/delayedrun_finished_flag ];do #see /usr/sbin/delayedrun.
 sleep 2
 EXCNT=$(($EXCNT + 1))
 [ $EXCNT -gt 10 ] && break #precaution
done


please_install() {
	gtkdialog-splash -bg orange -close box -text "Please install $1"
	exit
}

case $1 in
 camera)
  which pupcamera 2>&1 >/dev/null || please_install "pupcamera"
  pupcamera &
 ;;
 android-device)
  which mtpdevice 2>&1 >/dev/null || please_install "mtpdevice"
  mtpdevice mount &
 ;;

esac
